/**
 * Copyright (C) 2015 Red Hat, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.util;
import io.fabric8.kubernetes.api.model.*;
import io.fabric8.kubernetes.client.*;
import io.fabric8.kubernetes.client.Config;
import io.fabric8.kubernetes.client.ConfigBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.System;

import java.util.List;

public class GetPodStatus {
    private static final Logger logger = LoggerFactory.getLogger(GetPodStatus.class);

    public static void main(String[] args) throws InterruptedException {
        Config config = new ConfigBuilder()
                .build();
        KubernetesClient client = new DefaultKubernetesClient(config);

        try {
            PodList myPods = client.pods().inNamespace("kube-system").list();
            List<Pod> items = myPods.getItems();
            for (Pod item : items) {
                System.out.println(item + "PodName:" + item.getMetadata().getName() + "  HostIP:" + item.getStatus().getHostIP() +  "PodIP:" + item.getStatus().getPodIP());
            }

            //log("myPods " + myPods);
        }catch (KubernetesClientException e) {
                logger.error(e.getMessage(), e);
        } finally {
            client.close();
        }
    }


    private static void log(String action, Object obj) {
        logger.info("{}: {}", action, obj);
    }

    private static void log(String action) {
        logger.info(action);
    }
}
